<?php
class Uuch_CustomVar{
    
    private $vars;
    
    /**
     * 自定义变量:用户来源变量名称
     */
    const NAME_SOURCE = 'source';


    public function __construct() {
        $this->vars = array();
    }
    
    /**
     * 设置Google分析代码
     * @param int $index 分析代码位置，值只能是1到5之间，同一页上不能重复
     * @param string $name 变量名
     * @param string $value 值
     * @param int $level 变量级别
     */
    public function setVar($index,$name,$value,$level){
        $this->vars[]=array('index'=>$index,'name'=>$name,'value'=>$value,'level'=>$level);
    }
    
    public function getJs(){
        $js ='';
        foreach ($this->vars as $var) {
            $js = $js."_gaq.push(['_setCustomVar',".$var['index'].",'".$var['name']."','".$var['value']."',".$var['level']."]);\n";
            
        }
        return $js;
    }
    
    const LEVEL_visitor=1;
    
    const LEVEL_session =2;
    
    const LEVEL_page=3;
}